package com.gorkr.labuladong.data_struct.array;

/**
 * @author gorkr
 * @date 2022/06/03 16:45
 **/
public class E303RangeSumQueryImmutable {

    private int[] preSum;

    public E303RangeSumQueryImmutable(int[] nums) {

        //preSum[0] = 0 方便计算
        preSum = new int[nums.length + 1];

        for (int i = 1; i <= nums.length; i++) {
            preSum[i] = preSum[i - 1] + nums[i - 1];
        }
    }

    public int sumRange(int left, int right) {
        return preSum[right+1] - preSum[left];

    }


}
    